<?php
include ("header.php");
/*
 * error_reporting(E_ALL); ini_set('display_errors', 1);
 */
?>

<div class="container-fluid" style="padding-bottom: 10px;"></div>

<div class="container-fluid">
	<div class="row well">
		<table class="table table-striped ">
			<tr class=info>
				<th>#</th>
				<th>Date</th>
				<th>Route</th>
				<th>Distance</th>
				<th>Participants</th>
				<th>Remarks</th>
				<!-- <th># Doctors</th>
				<th># Assistants</th>
				<th>Remarks</th> -->
			</tr>
			<?php
			include 'dbconnection.php';
			
			$sql = "SELECT * FROM drive_record WHERE CAR_NO = '" . $carNo . "' ORDER BY START_DATETIME DESC;";
			$result = mysql_query ( $sql );
			$index = 1;
			while ( $row = mysql_fetch_array ( $result ) ) {
				// echo strtotime($time)date_diff($row['START_DATETIME'], $row['END_DATETIME']);
				/*
				 * $startDate = new DateTime(); $startDate->setTimestamp(strtotime($row['START_DATETIME'])); $endDate = new DateTime(); $endDate->setTimestamp(strtotime($row['END_DATETIME']));
				 */
				
				// echo date_diff($startDate,$endDate);
				// $startDate = date('Y-m-d H:i',strtotime($row['START_DATETIME']));
				// $endDate = date('Y-m-d H:i',strtotime($row['END_DATETIME']));
				
				/*
				 * sprintf ( "%d Days, %d Hours, %d Mins, %d Seconds", intval( $diff / 86400 ), intval( ( $diff % 86400 ) / 3600), intval( ( $diff / 60 ) % 60 ), intval( $diff % 60 ) );
				 */
				?>
			
			<tr class="records">
				<td><div class="col-sm-12">
						<div class="col-sm-12">
							<?php echo $index++; ?>
						</div>
					</div></td>
				<td><div class="col-sm-12">
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Start</span><span
								class="col-sm-12"><?php echo "&nbsp;".$row['START_DATETIME']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">End</span><span
								class="col-sm-12"><?php echo "&nbsp;".$row['END_DATETIME']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Duration</span><span
								class="col-sm-12">
								<?php
									$diff = strtotime ( $row ['END_DATETIME'] ) - strtotime ( $row ['START_DATETIME'] );
									echo intval ( ($diff % 86400) / 3600 ) . " hours";
								?>
							</span>
						</div>
					</div></td>
				<td><div class="col-sm-12">
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">From</span><span
								class="col-sm-12"><?php echo "&nbsp;".$row['FROM']?>&nbsp;</span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">To</span><span
								class="col-sm-12"><?php echo "&nbsp;".$row['TO']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Visited Places</span><span
								class="col-sm-12"><?php echo "&nbsp;".$row['VISITED_PLACES']?></span>
						</div>
					</div></td>
				<td><div class="col-sm-12">
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Start Odometer (Km)</span>
							<span class="col-sm-12"><?php echo "&nbsp;".$row['START_ODOMETER']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">End Odometer (Km)</span>
							<span class="col-sm-12"><?php echo "&nbsp;".$row['END_ODOMETER']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Distance (Km)</span>
							<span class="col-sm-12"><?php echo "&nbsp;".($row['END_ODOMETER']-$row['START_ODOMETER'])?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Fuel Topup Amount</span>
							<span class="col-sm-12"><?php echo "&nbsp;".$row['AMOUNT_FUEL_TOPUP']?></span>
						</div>
					</div></td>
				<td><div class="col-sm-12">
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Patients</span> <span
								class="col-sm-12"><?php echo "&nbsp;".$row['NUM_PATIENTS']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Doctors</span> <span
								class="col-sm-12"><?php echo "&nbsp;".$row['NUM_DOCTORS']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Assistants</span> <span
								class="col-sm-12"><?php echo "&nbsp;".$row['NUM_ASSISTANTS']?></span>
						</div>
					</div></td>
				<td>
					<div class="col-sm-12">
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Car comments</span> <span
								class="col-sm-12"><?php echo "&nbsp;".$row['CAR_COMMENT']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Tool comments</span>
							<span class="col-sm-12"><?php echo "&nbsp;".$row['TOOL_COMMENT']?></span>
						</div>
						<div class="col-sm-12">
							<span class="label label-default col-sm-12">Other comments</span>
							<span class="col-sm-12"><?php echo "&nbsp;".$row['REMARK']?></span>
						</div>
					</div>
				</td>
			</tr>

			
			<?php
			}
			mysql_close ( $con );
			?>
			
			

		</table>
	</div>
</div>


<?php include("footer.php");?>